
#pragma once

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

#include <iostream>

using namespace cv;

namespace course_01_read
{

    /// <summary>
    /// //开始启用cv函数从路径打开图片
    /// </summary>
    /// <param name="imgPath"></param>
    void read_show(std::string imgPath) //开始启用cv函数打开图片
    {
        std::cout << imgPath << std::endl;
        Mat img = imread(imgPath); // imagePath图片的路径
        // namedWindow("input",WINDOW_FREERATIO);
        imshow("input", img);
        waitKey(0);
        // destroyAllWindows(); //关闭窗口
    }

    /// <summary>
    /// //开始启用cv函数打开图片举证
    /// </summary>
    /// <param name="src"></param>
    void read_show(Mat src)
    {
        // namedWindow("input",WINDOW_FREERATIO);
        imshow("input", src);
        waitKey(0);
        // destroyAllWindows(); //关闭窗口
    }


    /// <summary>
    /// //开始启用录像播放
    /// </summary>
    /// <param name="videoPath"></param>
    void read_camera(std::string videoPath)
    {
         std::cout << videoPath << std::endl;
        VideoCapture capture(videoPath);
        Mat image;
        //为了持续播放需要循环  其实就是将每帧图循环放到一个画面上
        while (true)
        {
            if (image.empty()) { break; }

            capture.read(image);
            imshow("Image", image);

            //esc 退出
            int c = waitKey(1);
            if (c == 27) { break; } 
        }
    }


    /// <summary>
    /// 开始启用摄像头播放
    /// </summary>
    void read_webcam( )
    { 
        //直接获取默认摄像头
        VideoCapture capture;
        capture.open(0,CAP_DSHOW);
        Mat image;
        //为了持续播放需要循环  其实就是将每帧图循环放到一个画面上
        while (true)
        {
            capture.read(image);
          //  if (image.empty()) { break; }
            imshow("Image", image);

            //esc 退出
            int c = waitKey(1); 
            if (c == 27) { break; } 
        }
    }
}